<!DOCTYPE html>
<html>
<head>
    <#include "/includes/base.ftl"/>
    <link href="/static/index/css/shoping-cart.css" rel="stylesheet" type="text/css"/>
    <script>
        $(function () {

            $('#bottomId .kaola-bottom-text1').eq(1).addClass('text2');
            $('#shopcart').attr('src', '/static/index/images/shop-cart2.png');
            var jsonStr = cookieFun.getCookie('goods');
            $.ajax({
                type: "post",
                url: "/index/index/shopCartGet",
                data: JSON.stringify(jsonStr),
                contentType: 'application/json',
                success: function (data) {
                    if (data.status == 200) {
                        var html = '';
                        var money = 0;
                        for (let i = 0; i < data.data.length; i++) {
                            var line = data.data[i];
                            var count = 0;
                            for (let j = 0; j < jsonStr.length; j++) {
                                if (jsonStr[j].id == line.id) {
                                    count = jsonStr[j].count;
                                }
                            }
                            var moneyOne = (line.shopGoodsPrice / 100).toFixed(2);
                            money += moneyOne * count;
                            //console.log(count);
                            html +=
                                `<div class="index-goods">
				<span class="shop-cart-check2"><!-- <input type="checkbox" name="sub2" class="shopcart-input1 btn2"> --></span>
				<span class="index-goods-img"><img src="${r'${line.shopGoodsImg}'}"></span>
				<div class="index-goods-textbox">
					<span class="index-goods-text1">${r'${line.shopGoods}'}</span>
					<div class="index-goods-text2">￥<i class="priceJs">${r'${moneyOne}'}</i></div>
					<div class="shop-cart-box3">
						<#--<span class="shop-cart-subtract"></span>-->
						<input type="tel" size="4" value="${r'${count}'}" id="tb_count" class="shop-cart-numer"> 份
						<#--<span class="shop-cart-add"></span>-->
					</div>
				</div>
			</div>`;
                        }
                        $('#shopGoods').html(html);
                    }
                    $('#allTotal').html(money.toFixed(2));
                }
            });
            $('#goMoney').click(function () {
                var addressId = <#if RequestParameters['addressId']??>${RequestParameters['addressId']}<#else>0</#if>;
                if (addressId == 0) {
                    alert('请选择地址');
                    location.href = '/user/userAddress/getUseraddress';
                    return;
                }
                if (jsonStr.length == 0) {
                    alert('请选择商品');
                    location.href = '/index/index/index';
                    return;
                }

                $.ajax({
                    type: "post",
                    url: "/order/userOrder/goMoney?addressId=" + addressId,
                    data: JSON.stringify(jsonStr),
                    contentType: 'application/json',
                    success: function (data) {
                        if (data.status == 200) {
                            cookieFun.setCookie('goods', null);
                            location.href = '/order/userOrder/finish?orderId=' + data.data;
                        } else {
                            alert(data.data);
                        }
                    }
                });


            });


        });
    </script>
</head>
<body style="background: #F5F5F4;">
<div class="near-box">
    <div class="header">
        <#--<a href="" class="left"></a>-->
        购物车
        <#--<span class="shop-cart-htext1">编辑</span>-->
    </div>
    <div class="shop-cart-bigbox">
        <#--<div class="cart-title">先锋侠需要您的精确坐标</div>-->
        <div class="cart-title" onclick="location.href = '/user/userAddress/getUseraddress'">
            <#if address??>
                ${address}
            <#else >
                请选择地址
            </#if>
        </div>
        <div class="shop-cart-listbox1" id="shopGoods">

        </div>
    </div>
    <div class="shop-cart-total">
        <#--<label class="checkall">
            <span class="shop-cart-check1"><input type="checkbox" class="" id="ckAll"></span>
            全选
        </label>-->
        <span class="scart-total-text2">合计：￥</span>
        <span id="allTotal" class="scart-total-text3">0.00</span>
        <a class="scart-total-text4" id="goMoney">去结算<i id="selectedTotal"></i></a>
        <span class="delete hide"></span>
    </div>
    <#include "/includes/footer.ftl"/>
</div>
</body>
</html>